﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OP20.ViewModels
{
    public class ST11DeviceManagerViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public ST11DeviceManagerViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;

            InitParam();
            //开启定时器任务
            //DispatcherTimer dispatcherTimer = new DispatcherTimer();
            //dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
            //dispatcherTimer.Tick += OnTick;
            //dispatcherTimer.Start();


        }

        //private void OnTick(object? sender, EventArgs e)
        //{
        //    ST11WeighCurrentValue = OtherDevicePLCToPC_Global.testDatas[5].CurrentValue;
        //    ST11WeighResultValue = OtherDevicePLCToPC_Global.testDatas[5].ResultValue;
        //    ST11WeighResult = OtherDevicePLCToPC_Global.testDatas[5].Result[0];
        //}

        private void InitParam()
        {
            ST11SettingTime = WeightTime_Global.ST11WeightSettingTime;
        }



        #region 事件
        private DelegateCommand _GoBackCommand;

        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));

        void ExecuteGoBackCommand()
        {
            NavigationParameters param = new NavigationParameters();
            param.Add("StationName", "ST11");
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST11View, param);
        }


        private DelegateCommand _Reset0DownCmd;
        public DelegateCommand Reset0DownCmd =>
            _Reset0DownCmd ?? (_Reset0DownCmd = new DelegateCommand(ExecuteReset0DownCmd));

        void ExecuteReset0DownCmd()
        {
            OtherDevicePCToPLC_Global.WeighBoolArr[1] = true;
        }

        private DelegateCommand _Reset0UpCmd;
        public DelegateCommand Reset0UpCmd =>
            _Reset0UpCmd ?? (_Reset0UpCmd = new DelegateCommand(ExecuteReset0UpCmd));

        void ExecuteReset0UpCmd()
        {
            OtherDevicePCToPLC_Global.WeighBoolArr[1] = false;

        }

        private DelegateCommand _PowerOffCommand;
        public DelegateCommand PowerOffCommand =>
            _PowerOffCommand ?? (_PowerOffCommand = new DelegateCommand(ExecutePowerOffCommand));

        void ExecutePowerOffCommand()
        {
            OtherDevicePCToPLC_Global.bIn8 = true;
        }


        private DelegateCommand _UnPowerOffCommand;
        public DelegateCommand UnPowerOffCommand =>
            _UnPowerOffCommand ?? (_UnPowerOffCommand = new DelegateCommand(ExecuteUnPowerOffCommand));

        void ExecuteUnPowerOffCommand()
        {
            OtherDevicePCToPLC_Global.bIn8 = false;

        }

        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));

        void ExecuteTextChangeCommand(string p)
        {
            switch (p)
            {
                case "ST11SettingTime":
                    WeightTime_Global.ST11WeightSettingTime = ST11SettingTime;
                    break;
                default:
                    break;
            }
        }
        #endregion

        #region 属性
       
        private short _ST11SettingTime;
        public short ST11SettingTime
        {
            get { return _ST11SettingTime; }
            set { SetProperty(ref _ST11SettingTime, value); }
        }
        #endregion


    }
}
